/**
 * <pre>
 * apexcns / ConfigUtil.java
 * com.apexcns.xdp.common.config Class
 * ConfigUtil
 * <br>
 * 
 * <br>
 * @author hLee / apexcns,Inc.
 * @version 1.0
 * @see javadoc
 * @since 2012. 9. 14.
 * </pre>
 */
package com.ophelisis.common.config;

import java.io.File;

import com.ophelisis.actions.system.Login;
import com.ophelisis.common.util.FileUtil;

/** <pre>
 * Class : com.apexcns.xdp.common.config.ConfigUtil / ConfigUtil.java
 * 	Define Class Object : 
 * <br>
 * </pre>
 * @author hLee / apexcns,Inc.
 * @version 1.0
 * @see javadoc
 * @since 2012. 9. 14.
 */

public class ConfigUtil {
    /**
     * <pre>
     * Method : ConfigUtil.getAppHome()
     * 		"apexcns.configBase"
     * <br>
     * 	return type of String
     * <br>
     * @return 
     * </pre>
     */
	public static String getAppHome() {
		return getConfigBase();
	}
	
	public static String getAppHome(String dir) {
	    String path = getConfigBase();
	    	if (new File(path + dir).exists()) {
	    	    return path;
	    	}
	    	path += ".." + FileUtil.FS;
	    	if (new File(path + dir).exists()) {
	    	    return path;
	    	}
	    	return getConfigBase();
	}
	private static String getConfigBase() {
		return System.getProperty("apexcns.configBase", Login.class.getResource("").getPath() + "../../../../");
	}

	/**
	 * 0. ancmon.config
	 * 0. ancmon.home(user.dir) + /resources/config-module.xml
	 * @return
	 */
	public static String getCollectorConfigModuleFile() {
    	String dirName = "";
		String appConfig = System.getProperty("app.config");
		if (appConfig != null) return appConfig;
		return getAppHome(dirName) + dirName + "config-module.xml";
	}

	public static void main(String[] args) {
	    getAppHome("resources");
	}
}
